package com.zwf.mapper;

import com.zwf.dto.GoodsSalesDTO;
import com.zwf.entity.OrderDetail;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @Author zwf
 * @date 2024/2/12 10:06
 */
@Mapper
public interface OrderDetailMapper {

    /**
     * 批量插入n条数据
     * @param orderDetails
     */
    void addBatch(List<OrderDetail> orderDetails);

    /**
     * 动态条件查询订单详情
     * @param orderDetail
     * @return
     */
    List<OrderDetail> list(OrderDetail orderDetail);

    /**
     * 查询商品及其销量
     * @param map
     * @return
     */
    @Select("select od.name,sum(od.number) number from order_detail od left join orders o on od.order_id = o.id" +
            " where o.status=5 and o.order_time>#{begin} and o.order_time<#{end} group by od.name " +
            "order by sum(od.number) desc limit 0,10 ")
    List<GoodsSalesDTO> listGoodsSalesByMap(Map map);
}
